using GOPATH mode
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">

  <title>serialize - The Go Programming Language</title>

<link type="text/css" rel="stylesheet" href="/lib/godoc/style.css">

<link rel="search" type="application/opensearchdescription+xml" title="godoc" href="/opensearch.xml" />


<script>window.initFuncs = [];</script>
<script src="/lib/godoc/jquery.js" defer></script>



<script>var goVersion = "go1.12.12";</script>
<script src="/lib/godoc/godocs.js" defer></script>
</head>
<body>

<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
...
</div><!-- #lowframe -->

<div id="topbar" class="wide"><div class="container">
<div class="top-heading" id="heading-wide"><a href="/">The Go Programming Language</a></div>
<div class="top-heading" id="heading-narrow"><a href="/">Go</a></div>
<a href="#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
<form method="GET" action="/search">
<div id="menu">
<a href="/doc/">Documents</a>
<a href="/pkg/">Packages</a>
<a href="/project/">The Project</a>
<a href="/help/">Help</a>

<a href="/blog/">Blog</a>


<span class="search-box"><input type="search" id="search" name="q" placeholder="Search" aria-label="Search" required><button type="submit"><span><!-- magnifying glass: --><svg width="24" height="24" viewBox="0 0 24 24"><title>submit search</title><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/><path d="M0 0h24v24H0z" fill="none"/></svg></span></button></span>
</div>
</form>

</div></div>



<div id="page" class="wide">
<div class="container">


  <h1>
    Package serialize
    <span class="text-muted"></span>
  </h1>







<div id="nav"></div>


<!--
	Copyright 2009 The Go Authors. All rights reserved.
	Use of this source code is governed by a BSD-style
	license that can be found in the LICENSE file.
-->
<!--
	Note: Static (i.e., not template-generated) href and id
	attributes start with "pkg-" to make it impossible for
	them to conflict with generated attributes (some of which
	correspond to Go identifiers).
-->

	<script>
	document.ANALYSIS_DATA = null;
	document.CALLGRAPH = null;
	</script>

	
		
		<div id="short-nav">
			<dl>
			<dd><code>import "ServiceComputing/marshal/serialize"</code></dd>
			</dl>
			<dl>
			<dd><a href="#pkg-overview" class="overviewLink">Overview</a></dd>
			<dd><a href="#pkg-index" class="indexLink">Index</a></dd>
			
			
			</dl>
		</div>
		<!-- The package's Name is printed as title by the top-level template -->
		<div id="pkg-overview" class="toggleVisible">
			<div class="collapsed">
				<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
			</div>
			<div class="expanded">
				<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
				
				
			</div>
		</div>

		<div id="pkg-index" class="toggleVisible">
		<div class="collapsed">
			<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
		</div>
		<div class="expanded">
			<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>

		<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
			<div id="manual-nav">
			<dl>
			
			
				<dd><a href="#pkg-variables">Variables</a></dd>
			
			
				
				<dd><a href="#FormatAtom">func FormatAtom(v reflect.Value) string</a></dd>
			
				
				<dd><a href="#IsStruct">func IsStruct(s interface{}) bool</a></dd>
			
				
				<dd><a href="#JSONMarshal">func JSONMarshal(v interface{}) ([]byte, error)</a></dd>
			
				
				<dd><a href="#UnacceptedType">func UnacceptedType(i interface{}) bool</a></dd>
			
			
				
				<dd><a href="#TagOptions">type TagOptions</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#ParseTag">func ParseTag(tag string) (string, TagOptions)</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#TagOptions.HasOpt">func (t TagOptions) HasOpt(opt string) bool</a></dd>
				
			
				
				<dd><a href="#ValueWithTag">type ValueWithTag</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#New">func New(s interface{}) *ValueWithTag</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#ValueWithTag.Embeded">func (s *ValueWithTag) Embeded(val reflect.Value) (string, error)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#ValueWithTag.Marshal">func (s *ValueWithTag) Marshal() (string, error)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#ValueWithTag.StructFields">func (s *ValueWithTag) StructFields() []reflect.StructField</a></dd>
				
			
			
			</dl>
			</div><!-- #manual-nav -->

		

		
			<h3>Package files</h3>
			<p>
			<span style="font-size:90%">
			
				<a href="/src/ServiceComputing/marshal/serialize/marshal.go">marshal.go</a>
			
				<a href="/src/ServiceComputing/marshal/serialize/tag.go">tag.go</a>
			
			</span>
			</p>
		
		</div><!-- .expanded -->
		</div><!-- #pkg-index -->

		

		
		
			<h2 id="pkg-variables">Variables</h2>
			
				
				<pre>var (
    <span class="comment">// DefaulKey 默认标签名</span>
    <span id="DefaulTag">DefaulTag</span> = &#34;json&#34;

    <span class="comment">// ErrorUnaccceptType 错误：格式化过程中遇到不支持类型</span>
    <span id="ErrorUnacceptType">ErrorUnacceptType</span> = <a href="/pkg/fmt/">fmt</a>.<a href="/pkg/fmt/#Errorf">Errorf</a>(&#34;Unaccept type: reflect.Chan/reflect.Func&#34;)
)</pre>
			
		
		
			
			
			<h2 id="FormatAtom">func <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=4388:4427#L186">FormatAtom</a>
				<a class="permalink" href="#FormatAtom">&#xb6;</a>
				
				
			</h2>
			<pre>func FormatAtom(v <a href="/pkg/reflect/">reflect</a>.<a href="/pkg/reflect/#Value">Value</a>) <a href="/pkg/builtin/#string">string</a></pre>
			<p>
FormatAtom 对基本类型进行格式化
</p>

			
			

		
			
			
			<h2 id="IsStruct">func <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=1272:1305#L49">IsStruct</a>
				<a class="permalink" href="#IsStruct">&#xb6;</a>
				
				
			</h2>
			<pre>func IsStruct(s interface{}) <a href="/pkg/builtin/#bool">bool</a></pre>
			<p>
IsStruct 判断一个Value是否为结构体
</p>

			
			

		
			
			
			<h2 id="JSONMarshal">func <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=342:389#L8">JSONMarshal</a>
				<a class="permalink" href="#JSONMarshal">&#xb6;</a>
				
				
			</h2>
			<pre>func JSONMarshal(v interface{}) ([]<a href="/pkg/builtin/#byte">byte</a>, <a href="/pkg/builtin/#error">error</a>)</pre>
			<p>
JSONMarshal 接收符合类型的任意值，并将其格式化为JSON
</p>

			
			

		
			
			
			<h2 id="UnacceptedType">func <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=4689:4728#L198">UnacceptedType</a>
				<a class="permalink" href="#UnacceptedType">&#xb6;</a>
				
				
			</h2>
			<pre>func UnacceptedType(i interface{}) <a href="/pkg/builtin/#bool">bool</a></pre>
			<p>
UnacceptedType 判断是否是不支持的类型，目前不支持reflect.Chan, reflect.Func
</p>

			
			

		
		
			
			
			<h2 id="TagOptions">type <a href="/src/ServiceComputing/marshal/serialize/tag.go?s=76:100#L1">TagOptions</a>
				<a class="permalink" href="#TagOptions">&#xb6;</a>
				
				
			</h2>
			<p>
TagOptions 标签中的选项部分
</p>

			<pre>type TagOptions []<a href="/pkg/builtin/#string">string</a></pre>

			

			

			
			
			

			
				
				<h3 id="ParseTag">func <a href="/src/ServiceComputing/marshal/serialize/tag.go?s=338:384#L9">ParseTag</a>
					<a class="permalink" href="#ParseTag">&#xb6;</a>
					
					
				</h3>
				<pre>func ParseTag(tag <a href="/pkg/builtin/#string">string</a>) (<a href="/pkg/builtin/#string">string</a>, <a href="#TagOptions">TagOptions</a>)</pre>
				<p>
ParseTag 解析tag，返回tag名与tag选项
</p>

				
				
			

			
				
				<h3 id="TagOptions.HasOpt">func (TagOptions) <a href="/src/ServiceComputing/marshal/serialize/tag.go?s=155:198#L1">HasOpt</a>
					<a class="permalink" href="#TagOptions.HasOpt">&#xb6;</a>
					
					
				</h3>
				<pre>func (t <a href="#TagOptions">TagOptions</a>) HasOpt(opt <a href="/pkg/builtin/#string">string</a>) <a href="/pkg/builtin/#bool">bool</a></pre>
				<p>
Has 检查标签中是否存在opt选项并返回
</p>

				
				
				
			
		
			
			
			<h2 id="ValueWithTag">type <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=871:958#L29">ValueWithTag</a>
				<a class="permalink" href="#ValueWithTag">&#xb6;</a>
				
				
			</h2>
			<p>
ValueWithTag 对reflect.Value进行封装，令其附带Tag
</p>

			<pre>type ValueWithTag struct {
<span id="ValueWithTag.Value"></span>    Value <a href="/pkg/reflect/">reflect</a>.<a href="/pkg/reflect/#Value">Value</a> <span class="comment">// 值</span>
<span id="ValueWithTag.Tag"></span>    Tag   <a href="/pkg/builtin/#string">string</a>        <span class="comment">// 标签</span>
}
</pre>

			

			

			
			
			

			
				
				<h3 id="New">func <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=1047:1084#L35">New</a>
					<a class="permalink" href="#New">&#xb6;</a>
					
					
				</h3>
				<pre>func New(s interface{}) *<a href="#ValueWithTag">ValueWithTag</a></pre>
				<p>
New 返回Value的ValueWithTag封装，若Value为指针会获取最终指向的值
</p>

				
				
			

			
				
				<h3 id="ValueWithTag.Embeded">func (*ValueWithTag) <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=2934:2999#L120">Embeded</a>
					<a class="permalink" href="#ValueWithTag.Embeded">&#xb6;</a>
					
					
				</h3>
				<pre>func (s *<a href="#ValueWithTag">ValueWithTag</a>) Embeded(val <a href="/pkg/reflect/">reflect</a>.<a href="/pkg/reflect/#Value">Value</a>) (<a href="/pkg/builtin/#string">string</a>, <a href="/pkg/builtin/#error">error</a>)</pre>
				<p>
Embeded 递归处理字段值并返回格式化字符串
</p>

				
				
				
			
				
				<h3 id="ValueWithTag.Marshal">func (*ValueWithTag) <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=1489:1537#L60">Marshal</a>
					<a class="permalink" href="#ValueWithTag.Marshal">&#xb6;</a>
					
					
				</h3>
				<pre>func (s *<a href="#ValueWithTag">ValueWithTag</a>) Marshal() (<a href="/pkg/builtin/#string">string</a>, <a href="/pkg/builtin/#error">error</a>)</pre>
				<p>
Marshal 根据ValueWithTag的Tag来解析结构体
</p>

				
				
				
			
				
				<h3 id="ValueWithTag.StructFields">func (*ValueWithTag) <a href="/src/ServiceComputing/marshal/serialize/marshal.go?s=4892:4951#L208">StructFields</a>
					<a class="permalink" href="#ValueWithTag.StructFields">&#xb6;</a>
					
					
				</h3>
				<pre>func (s *<a href="#ValueWithTag">ValueWithTag</a>) StructFields() []<a href="/pkg/reflect/">reflect</a>.<a href="/pkg/reflect/#StructField">StructField</a></pre>
				<p>
StructFields 返回结构体中导出的字段
</p>

				
				
				
			
		
	

	







<div id="footer">
Build version go1.12.12.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="/LICENSE">BSD license</a>.<br>
<a href="/doc/tos.html">Terms of Service</a> |
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>

</div><!-- .container -->
</div><!-- #page -->
</body>
</html>

